<?php

class GoodsController extends FrontBaseC {
    //商品内页
    public function actionDetail() {
        $good_id = (int) $_GET['gid'];
        $goods = GoodsModel::getOne($good_id);
        //判断是否蜘蛛
        if (!UrlClass::getrobot()) {
            if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] && $goods['ItemType'] < 10) {
                $domain = GuestDataModel::getDomain($_SERVER['HTTP_REFERER']);
                //以下来源域名不跳
                if (!in_array($domain['RootDomain'], array('baidu.com', 'so.com', 'soso.com', 'sogou.com', 'google.com', 'bing.com', 'yahoo.com', '360.cn', '2345.com', 'hao123.com', 'duba.com', 'uc123.com', 'qq.com'))) {
                    if (empty($goods['TaobaoUrl'])) {
                        $this->redirect($goods['DetailUrl']);
                    } else {
                        $this->redirect($goods['TaobaoUrl']);
                    }
                }
            }
        }
        if ($goods) {
            $this->assign('goods', $goods);
            $this->render();
        }else{
            $this->render('noGoodShow');                            
        }
    }

    public function actionCollect(){
        if(!yii::app()->user->isLogin()){
            $this->error('您没有登录,请登录');
        }
        //判断这个商品是否存在
        if(!GoodsModel::getOne($goodsID = Yii::app()->request->getParam('id'))){
            $this->error('找不到此商品');
        }
        $count = MemberCollectModel::collect(Yii::app()->request->getParam('id'), yii::app()->user->id);
        $this->ajaxReturn(array('status' => true, 'number' => $count));
    }

    public function actionCeshi(){

        $a = new Memcache;
        $a->addServer('127.0.0.1', 11211);
        $a->set('aa', array(12,3,4));
        print_r($a->get('aa'));exit;


        $redis = new Redis();
        $redis->pconnect('127.0.0.1', 6379);
        echo $redis->exists('abcd');exit;
        echo $redis->rPop('abcd');exit;
        echo $redis->exists('abcd');
        $redis->del('abcd');
        echo $redis->exists('abcd');
    }

}
